package com.xuanwei.admin.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xuanwei.core.response.ResultVO;
import com.xuanwei.core.service.IXwLoginLogService;
import com.xuanwei.dao.entity.XwLoginLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * @Author jiangyong
 * @Description TODO
 * @Date 2019/4/23 17:26
 **/
@RestController
@RequestMapping("/api/loginLog")
public class LoginLogService extends BasicController {


    @Autowired
    private IXwLoginLogService loginLogService;


    @RequestMapping(value ="list.do",method = RequestMethod.GET)
    public ResultVO list(Integer index,Integer pageSize){
        Page<XwLoginLog> page = getPage(index, pageSize);
        loginLogService.list(page);
        return ResultVO.successResult(page);
    }

    @RequestMapping(value ="delete.do",method = RequestMethod.GET)
    public ResultVO delete(String ids){
       if(StringUtils.isEmpty(ids)){
           return ResultVO.failResult("ids参数不能为空");
       }
        String[] split = ids.split("-");
        Integer[] id =new Integer[split.length];
        for(int i=0;i<split.length;i++){
            id[i]=Integer.parseInt(split[i]);
        }
        List<Integer> list = Arrays.asList(id);
        loginLogService.delete(list);
        return ResultVO.successResult("删除成功");
    }
}
